<!--河长考核统计页面-->
<style lang="less">
.count {
  margin: 15px;
  .white {
    display: flex;
    align-items: center;
  }
  .icon-btn {
    font-size: 20px;
    color: #555555;
  }
  .smallForm {
    display: inline-block;
  }
  .smallArr {
    width: 15%;
    display: inline-block;
  }
  .chart {
    margin-top: 20px;
    height: 300px;
  }
  .ivu-table td,
  .ivu-table th {
    height: 35px !important;
  }
}
.user-count {
  .ivu-modal-body {
    margin-bottom: 15px !important;
  }
}
// 巡查频率规则
.frequency-content {
  font-size: 14px;
  .title {
    font-weight: bold;
  }
}
.mt20 {
  margin-top: 20px;
}
</style>

<template>
  <div class="count">
    <Card :bordered="false">
      <p slot="title"
         class="white">统计分析 > <span class="select-font">河长考核统计</span><span style="margin-left:25px;">助理巡查总次数: {{all_num_ass}}</span><span style="margin-left:25px">巡查总次数: {{all_num}}</span></p>
      <div>
        <Form :model="searchItem"
              class="smallForm">
          <Input v-model="searchItem.cherf_name"
                 :maxlength="30"
                 style="width:200px;margin-right: 30px"
                 placeholder="请输入河长名字" />
          <area-select @getData="getAreaData"
                       :multipleType="multiple"
                       style="width: 200px;margin-right: 30px"></area-select>
          <DatePicker type="month"
                      v-show="assMode=='MONTH'"
                      :value="searchItem.time_sign"
                      @on-change="changeTime"
                      placeholder="请选择时间"
                      format="yyyy年MM月"
                      style="width: 200px;margin-right: 30px"></DatePicker>
          <DatePicker type="year"
                      v-show="assMode=='QUARTER'"
                      :value="searchItem.year"
                      @on-change="changeYear"
                      placeholder="请选择时间"
                      style="width: 200px;margin-right: 30px"></DatePicker>
          <Select v-show="assMode=='QUARTER'"
                  v-model="quarter"
                  style="width:200px"
                  @on-change="getQuarter"
                  placeholder="请选择季度">
            <Option v-for="item in quarterList"
                    :value="item.value"
                    :key="item.value">{{ item.label }}</Option>
          </Select>
          <Select v-model="assMode"
                  style="width:200px"
                  placeholder="请选择考核模式">
            <Option v-for="item in modeList"
                    :value="item.value"
                    :key="item.value">{{ item.label }}</Option>
          </Select>
          <Select v-model="passTag"
                  style="width:200px; margin-left: 30px"
                  @on-change="passState"
                  placeholder="请选择是否达标">
            <Option v-for="item in passList"
                    :value="item.value"
                    :key="item.value">{{ item.label }}</Option>
          </Select>
        </Form>
        <Button type="info"
                style="margin-left:25px"
                @click="getData(1)">搜索</Button>
        <Button type="primary"
                style="margin-left:25px"
                @click="exportAllData(1)">导出数据</Button>
      </div>
    </Card>
    <div>
      <Col span="24">
      <Table :data="countData"
             @on-row-click="getAllData"
             :columns="countColumns"
             stripe></Table>
      <Page class="pull-right"
            :total="Page.total"
            :current="Page.current"
            :page-size="Page.pageSize"
            size="small"
            show-total
            @on-change="changePage"></Page>
      </Col>
      <Col span="12">
      <Tabs>
        <TabPane label="巡查总次数"
                 name="巡查总次数">
          <div class="chart patrolnum">

          </div>
        </TabPane>
        <TabPane label="巡查总长度(m)"
                 name="巡查总长度">
          <div class="chart patrolDis">

          </div>
        </TabPane>
        <TabPane label="巡查总时间(s)"
                 name="巡查总时间">
          <div class="chart patroltime">

          </div>
        </TabPane>
      </Tabs>
      </Col>
      <Col span="12">
      <div class="chart patrolcircle">

      </div>
      <!-- <Tabs @on-click="changeReport">
                    <TabPane label="举报次数" name="举报次数">
                        <div class="chart">

                        </div>
                    </TabPane>
                </Tabs> -->
      </Col>
    </div>
    <Modal class="user-count"
           title="查看巡查的河流"
           v-model="riverModal"
           :mask-closable="false"
           width="800">
      <Table :data="riverData"
             :columns="riverColumns"
             stripe></Table>
      <Page class="pull-right"
            :total="riverPage.total"
            :current="riverPage.current"
            :page-size="riverPage.pageSize"
            size="small"
            show-total
            @on-change="changeRiverPage"></Page>
    </Modal>
    <Modal class="user-count"
           v-model="patrolModal"
           :mask-closable="false"
           title="查看巡河"
           width="1200">
      <Table ref="table"
             :data="patrolData"
             :columns="patrolColumns"
             stripe></Table>
      <div slot="footer">
        <Button type="success"
                @click="exportData">导出数据</Button>
        <Button @click="patrolModal = false">取消</Button>
      </div>
      <Page class="pull-right"
            :total="riverPage.total"
            :current="riverPage.current"
            :page-size="riverPage.pageSize"
            size="small"
            show-total
            @on-change="changeRiverPage"></Page>
    </Modal>
    <Modal class="user-count"
           v-model="frequencyModal"
           :mask-closable="false"
           title="巡查频率规则"
           width="800">
           <div class="frequency-content">
             <div>
               <div class="title">巡查频率</div>
               <p>镇级：1-10、11-20、21-月底。</p>
               <p>村级：1-7、8-14、15-21、22-月底。</p>
             </div>
             <div class="mt20">
               <div class="title">扣分规则</div>
                <p>1、巡河次数未满足条件的，只扣次数分，不扣频率分，即每人每次扣1分。</p>
                <p>2、巡河次数已达标，但频率不满足，则只扣频率分，即每人每次扣0.5分。</p>
             </div>
           </div>
    </Modal>
    <Modal class="user-count"
           v-model="deductModal"
           :mask-closable="false"
           title="扣分规则"
           width="1200">
           <Table ref="table"
             :data="deductData"
             :columns="deductColumns"
             stripe></Table>
    </Modal>
  </div>
</template>

<script>
import { ajaxPost } from 'global/axios';
import storage from 'good-storage';
import { userLineChart, userCircle } from 'common/js/echart';
import areaSelect from 'public/areaSelect';
import tableDropdown from 'public/tableHeaderDropdown';
import { domain2 } from 'global/setting';

export default {
  components: {
    'area-select': areaSelect,
  },
  data() {
    return {
      urlChiefsList: '/stat/chiefs/list',
      urlPatrolCount: '/stat/chiefs/stat_chief_byday',
      urlPatrolCircle: '/stat/chiefs/patrolByriver',
      urlPatrolList: '/emergency/patrol/listall',
      urlDao: '/emergency/patrol/makexml',
      urlCheck: '/stat/chiefs/checkstat',
      areaList: [],
      riverData: [],
      patrolModal: false,
      frequencyModal: false,
      multiple: true,
      patrolData: [],
      all_num: 0,
      all_num_ass: 0,
      assMode: 'MONTH',
      modeList: [
        {
          value: 'MONTH',
          label: '月份模式',
        },
        {
          value: 'QUARTER',
          label: '季度模式',
        },
      ],
      quarter: '1',
      quarterList: [
        {
          value: '1',
          label: '第一季度',
        },
        {
          value: '2',
          label: '第二季度',
        },
        {
          value: '3',
          label: '第三季度',
        },
        {
          value: '4',
          label: '第四季度',
        },
      ],
      passTag: 1,
      passList: [
        {
          value: 1,
          label: '是',
        },
        {
          value: 0,
          label: '否',
        },
      ],
      patrolColumns: [
        {
          type: 'index',
          width: 60,
          align: 'center',
        },
        {
          title: '河长',
          key: 'personel_name',
        },
        {
          title: '区',
          render: (h, params) => {
            return h('div', {}, params.row.location.area)
          }
        },
        {
          title: '镇',
          render: (h, params) => {
            return h('div', {}, params.row.location.town)
          }
        },
        {
          title: '河流名称',
          key: 'river_name',
        },
        {
          title: '本次巡河景观图',
          align: 'center',
          key: 'sec_length',
        },
        {
          title: '本次巡河举报数量',
          align: 'center',
          key: 'report_length',
        },
        {
          title: '巡查日期',
          key: 'end_time',
        },
        {
          title: '巡查时间',
          key: 'runtime',
        },
      ],
      riverColumns: [
        {
          title: '河流名称',
          align: 'center',
          key: 'river_name',
        },
        {
          title: '开始时间',
          align: 'center',
          render: (h, param) => {
            return h('div', {}, param.row.start_time);
          },
        },
        {
          title: '结束时间',
          align: 'center',
          render: (h, param) => {
            return h('div', {}, param.row.end_time);
          },
        },
        {
          title: '巡查时间',
          align: 'center',
          key: 'runtime',
        },
        {
          title: '巡河距离(m)',
          align: 'center',
          key: 'distance',
        },
      ],
      riverModal: false,
      searchItem: {
        time_sign: '',
        cherf_name: '',
        area: '',
        user_type: '0,1,2,3|#|in',
        river_name: '',
        year: ''
      },
      saveType: 0,
      saveRow: {},
      Page: {
        current: 1,
        pageSize: 8,
        total: 0,
      },
      riverPage: {
        current: 1,
        pageSize: 10,
        total: 0,
      },
      timeList: [],
      countData: [],
      actionPage: '',
      rowDate: '', // 当前行日期
      countColumns: [
        {
          title: '河长名',
          key: 'realname',
          render: (h, params) => {
            return h('div', {}, params.row.realname);
          },
        },
        {
          title: '等级',
          key: 'user_type',
          renderHeader: (h, params) => {
            return h(tableDropdown, {
              props: {
                placement: 'bottom-start',
                showArrow: true,
                content: '等级',
                data: [
                  { value: 'all', name: '全部' },
                  { value: '3', name: '市级河长' },
                  { value: '2', name: '区级河长' },
                  { value: '1', name: '镇级河长' },
                  { value: '0', name: '村级河长' },
                ],
              },
              on: {
                'on-choosed': data => {
                  if (data !== 'all') {
                    this.searchItem.user_type = data;
                    this.getData(1);
                  } else {
                    this.searchItem.user_type = '0,1,2,3|#|in';
                    this.getData(1);
                  }
                },
              },
            });
          },
          render: (h, params) => {
            if (params.row.user_type === '0') {
              return h('div', {}, '村级河长');
            } else if (params.row.user_type === '1') {
              return h('div', {}, '镇级河长');
            } else if (params.row.user_type === '2') {
              return h('div', {}, '区级河长');
            } else if (params.row.user_type === '3') {
              return h('div', {}, '市级河长');
            }
          },
        },
        {
          title: '巡查总时间',
          align: 'center',
          key: 'num_time_string',
        },
        {
          title: '巡查距离总长度(m)',
          align: 'center',
          key: 'num_dis',
        },
        {
          title: '平均巡查时间',
          align: 'center',
          key: 'avg_time_string',
        },
        {
          title: '平均巡查距离(m)',
          align: 'center',
          key: 'avg_dis',
        },
        {
          title: '上传景观数量',
          align: 'center',
          key: 'scen_num',
        },
        {
          title: '巡查总次数',
          align: 'center',
          key: 'num',
          render: (h, params) => {
            return h(
              'div',
              {
                style: {
                  cursor: 'pointer',
                },
                on: {
                  click: () => {
                    this.rowDate = `${params.row.first_end_time}|#|${params.row.last_end_time}`;
                    this.getPatrolModal(params.row.username, 1);
                    this.patrolModal = true;
                  },
                },
              },
              params.row.num
            );
          },
        },
        {
          title: '助理巡查次数',
          align: 'center',
          key: 'num_ass',
          render: (h, params) => {
            return h(
              'div',
              {
                style: {
                  cursor: 'pointer',
                },
                on: {
                  click: () => {
                    this.rowDate = `${params.row.first_end_time}|#|${params.row.last_end_time}`;
                    this.getPatrolModal(params.row.username, 1, 1);
                    this.patrolModal = true;
                  },
                },
              },
              params.row.num_ass
            );
          },
        },
        {
          title: '达标次数',
          align: 'center',
          key: 'pass_count',
        },
        {
          title: '巡查频率',
          align: 'center',
          render: (h, params) => {
            return h('div', {}, params.row.frequency_count !== null ? params.row.frequency_count : '');
          },
          renderHeader: (h, index) => {
            return h('div', [
              h('span', '巡查频率'), 
              h('Icon', { 
                props: { type: 'ios-help-circle-outline' },
                style: { 
                  cursor: 'pointer',
                  fontSize: '16px',
                  fontWeight: 'bold'
                },
                on: {
                  click: () => {
                    this.frequencyModal = true;
                  }
                }
              })
            ]);
          }
        },
        {
          title: '扣分',
          align: 'center',
          render: (h, params) => {
            if(params.row.deduct_score === 0){
              return h(
                'div',
                params.row.deduct_score
              );
            }else{
              return h(
                'div',
                {
                  style: {
                    cursor: 'pointer',
                  },
                  on: {
                    click: () => {
                      this.deductModal = true;
                      this.deductData = params.row.deduction_items && params.row.deduction_items.length > 0 ? params.row.deduction_items : [];
                    },
                  },
                },
                params.row.deduct_score
              );
            }
          }
        },
        {
          title: '是否达标',
          align: 'center',
          key: 'pass',
        },
        {
          title: '操作',
          width: 120,
          render: (h, params) => {
            return h(
              'Button',
              {
                props: {
                  type: 'primary',
                  size: 'small',
                },
                style: {
                  marginRight: '5px',
                },
                on: {
                  click: () => {
                    this.saveRow = params.row;
                    this.getPatrol(params.row);
                  },
                },
              },
              '查看巡查河流'
            );
          },
        },
      ],
      saveName: '',
      // 扣分规则
      deductModal: false,
      deductData: [],
      deductColumns: [
        {
          title: '扣分值',
          align: 'center',
          key: 'deduct_score',
        },
        {
          title: '检查内容',
          align: 'center',
          key: 'item_name',
        },
        {
          title: '说明',
          align: 'center',
          key: 'description',
        }
      ]
    };
  },

  methods: {
    exportAllData(page = 1, pageSize = 8) {
      let params = {
        data: {
          page,
          pageSize,
          order: { end_time: -1 },
          searchValue: {},
        },
        token: storage.session.get('token'),
        url: '/stat/chiefs/checkstatxml',
        success: res => {
          if (res.data.code === '0000') {
            let url = domain2 + res.data.result;
            fetch(url).then(res =>
              res.blob().then(blob => {
                let a = document.createElement('a');
                let url = window.URL.createObjectURL(blob);
                let filename = '巡查记录表';
                a.href = url;
                a.download = filename;
                a.click();
                window.URL.revokeObjectURL(url);
              })
            );
          } else {
            this.$Message.warning({
              content: `${res.data.message}`,
            });
          }
        },
      };

      if (this.searchItem.cherf_name !== '') {
        params.data.searchValue.realname = `${this.searchItem.cherf_name}|#|like`;
      }
      if (this.searchItem.user_type !== '') {
        params.data.searchValue.user_type = this.searchItem.user_type;
      }
      params.data.searchValue.check_mode = this.assMode;

      if (this.assMode == 'MONTH') {
        params.data.searchValue.end_time = this.searchItem.time_sign
          .replace('年', '-')
          .replace('月', '');
      } else {
        params.data.searchValue.year = this.searchItem.year;
        params.data.searchValue.end_time = this.quarter;
      }

      params.data.searchValue.pass = this.passTag == 1;

      if (
        this.searchItem.area !== undefined &&
        this.searchItem.area.length !== 0
      ) {
        if (this.multiple) {
          let arrArea = [];
          let arrTown = [];
          if (this.searchItem.area !== undefined) {
            if (this.searchItem.area.constructor === Array) {
              this.searchItem.area.map(item => {
                if (item.level === '2') {
                  arrArea.push(item.name);
                }
                if (item.level === '3') {
                  arrTown.push(item.name);
                }
              });
            } else {
              if (this.searchItem.area.level === '2') {
                arrArea.push(this.searchItem.area.name);
              }
              if (this.searchItem.area.level === '3') {
                arrTown.push(this.searchItem.area.name);
              }
            }

            let strArea = `${arrArea.join(',')}|#|in`;
            let strTown = `${arrTown.join(',')}|#|in`;
            if (arrArea.length !== 0) {
              params.data.searchValue['departments.area'] = strArea;
            }
            if (arrTown.length !== 0) {
              params.data.searchValue['departments.town'] = strTown;
            }
          }
        } else {
          params.data.searchValue['departments.area'] =
            this.searchItem.area.level === '2' ? this.searchItem.area.name : '';
          params.data.searchValue['departments.town'] =
            this.searchItem.area.level === '3' ? this.searchItem.area.name : '';
        }
      }
      console.log(params);
      ajaxPost(params);
    },

    getData(page = 1, pageSize = 8) {
      let params = {
        data: {
          page,
          pageSize,
          order: { end_time: -1 },
          searchValue: {},
        },
        url: this.urlCheck,
        token: storage.session.get('token'),
        success: res => {
          this.$Loading.finish();
          this.countData = res.data.result.result;
          if (this.countData == undefined) {
            this.Page.total = 0;
            this.all_num = 0;
            this.all_num_ass = 0;
            return;
          }
          this.countData.map(item => {
            item.pass = item.pass ? '是' : '否';
          });

          if (this.countData.length == 0) {
            let aa = {
              first_end_time: '2080-01-01 00:00:00',
              last_end_time: '2080-01-01 00:00:01',
              username: 'zhangdingji',
            };
            this.getPatrolData(aa);
            this.getPatrolCircle(aa);
          } else {
            this.getPatrolData(this.countData[0]);
            this.getPatrolCircle(this.countData[0]);
          }
          this.Page.total = res.data.result.totalSize;
          this.all_num = res.data.result.all_num;
          this.all_num_ass = res.data.result.all_num_ass;
        },
      };
      if (this.searchItem.cherf_name !== '') {
        params.data.searchValue.realname = `${this.searchItem.cherf_name}|#|like`;
      }
      if (this.searchItem.user_type !== '') {
        params.data.searchValue.user_type = this.searchItem.user_type;
      }
      params.data.searchValue.check_mode = this.assMode;

      if (this.assMode == 'MONTH') {
        params.data.searchValue.end_time = this.searchItem.time_sign
          .replace('年', '-')
          .replace('月', '');
      } else {
        params.data.searchValue.year = this.searchItem.year;
        params.data.searchValue.end_time = this.quarter;
      }

      params.data.searchValue.pass = this.passTag == 1;

      if (
        this.searchItem.area !== undefined &&
        this.searchItem.area.length !== 0
      ) {
        if (this.multiple) {
          let arrArea = [];
          let arrTown = [];
          if (this.searchItem.area !== undefined) {
            if (this.searchItem.area.constructor === Array) {
              this.searchItem.area.map(item => {
                if (item.level === '2') {
                  arrArea.push(item.name);
                }
                if (item.level === '3') {
                  arrTown.push(item.name);
                }
              });
            } else {
              if (this.searchItem.area.level === '2') {
                arrArea.push(this.searchItem.area.name);
              }
              if (this.searchItem.area.level === '3') {
                arrTown.push(this.searchItem.area.name);
              }
            }

            let strArea = `${arrArea.join(',')}|#|in`;
            let strTown = `${arrTown.join(',')}|#|in`;
            if (arrArea.length !== 0) {
              params.data.searchValue['departments.area'] = strArea;
            }
            if (arrTown.length !== 0) {
              params.data.searchValue['departments.town'] = strTown;
            }
          }
        } else {
          params.data.searchValue['departments.area'] =
            this.searchItem.area.level === '2' ? this.searchItem.area.name : '';
          params.data.searchValue['departments.town'] =
            this.searchItem.area.level === '3' ? this.searchItem.area.name : '';
        }
      }

      if (pageSize === 0) {
        params.success = res => {
          res.data.result.result.map(item => {
            item.realname = item.realname;
            if (item.user_type === '0') {
              item.user_type = '村级河长';
            } else if (item.user_type === '1') {
              item.user_type = '镇级河长';
            } else if (item.user_type === '2') {
              item.user_type = '区级河长';
            } else if (item.user_type === '3') {
              item.user_type = '市级河长';
            }
          });
          this.$refs.table.exportCsv({
            filename: '河长巡河数据',
            columns: this.countColumns.filter((col, index) => index < 8),
            data: res.data.result.result,
            quoted: true,
          });
        };
      }
      ajaxPost(params);
    },
    getPatrolData(row) {
      let params = {
        data: {
          start_time: row.first_end_time,
          end_time: row.last_end_time,
          username: row.username,
        },
        url: this.urlPatrolCount,
        token: storage.session.get('token'),
        success: res => {
          this.$Loading.finish();
          let xaxis = [];
          let num = [];
          let dis_num = [];
          let time = [];
          if (res.data.result && res.data.result.length > 0) {
            res.data.result.map(item => {
              xaxis.push(item._id.substr(5, 10));
              num.push(item.num);
              dis_num.push(item.dis_sum);
              time.push(item.time_sum);
            });
          }
          let patrolnum = document.getElementsByClassName('patrolnum')[0];
          let patroltime = document.getElementsByClassName('patroltime')[0];
          let patrolDis = document.getElementsByClassName('patrolDis')[0];
          userLineChart(xaxis, dis_num, patrolDis, ['巡查距离总长度'], 'bar');
          userLineChart(xaxis, num, patrolnum, ['巡查总次数'], 'line');
          userLineChart(xaxis, time, patroltime, ['巡查总时间'], 'bar');
        },
      };
      ajaxPost(params);
    },
    getQuarter(q) {
      console.log(q);
    },

    passState(pass) {
      console.log(pass);
    },

    getPatrolCircle(row) {
      let params = {
        data: {
          start_time: row.first_end_time,
          end_time: row.last_end_time,
          username: row.username,
        },
        url: this.urlPatrolCircle,
        token: storage.session.get('token'),
        success: res => {
          let el = document.getElementsByClassName('patrolcircle')[0];
          let title = '巡查总时间河流比例';
          let data = [];
          let legend = [];
          if (res.data.result && res.data.result.length > 0) {
            res.data.result.map(item => {
              data.push({ value: item.time_sum, name: item._id });
              legend.push(item._id);
            });
          }
          userCircle(el, title, data, legend);
        },
      };
      ajaxPost(params);
    },
    getAllData(row) {
      this.getPatrolData(row);
      this.getPatrolCircle(row);
    },
    changePage(page) {
      this.getData(page);
      this.actionPage = page;
    },
    changeTime(data) {
      if (data[0] === '') {
        this.searchItem.time_sign = [];
        return;
      }
      console.log(`time_sign ${data}`);
      this.searchItem.time_sign = data;
    },
    changeYear(data) {
      this.searchItem.year = data;
    },
    changeRiverPage(data) {
      if (this.patrolModal) {
        this.getPatrolModal(this.saveName, data, this.saveType);
      } else {
        this.getPatrol(this.saveRow, data);
      }
    },
    getPatrol(row, page = 1) {
      let params = {
        data: {
          page,
          pageSize: this.riverPage.pageSize,
          searchValue: {
            username: row.username,
            end_time: `${row.first_end_time}|#|${row.last_end_time}`,
          },
          fieldName: [
            'patrol_no',
            'start_time',
            'end_time',
            'runtime',
            'river_name',
            'distance'
          ],
        },
        url: this.urlPatrolList,
        token: storage.session.get('token'),
        success: res => {
          this.riverData = res.data.result.result;
          this.riverPage.total = res.data.result.totalSize;
          this.riverModal = true;
        },
      };
      ajaxPost(params);
    },
    getPatrolModal(name, page, type = 0) {
      this.saveType = type;
      this.saveName = name;
      let params = {
        data: {
          page,
          pageSize: 10,
          searchValue: {
            patrol_is: '已结束',
            username: name,
          },
          basis: 2,
          order: { end_time: -1 },
        },
        url: this.urlPatrolList,
        token: storage.session.get('token'),
        success: res => {
          this.$Loading.finish();
          this.riverPage.total = res.data.result.totalSize;
          this.patrolData = res.data.result.result;
          this.patrolData.map(item => {
            item.sec_length = item.scenerys.length;
            item.report_length = item.reports.length;
          });
        },
      };
      let arrArea = [];
      let arrTown = [];
      if (this.searchItem.area && this.searchItem.area.length > 0) {
        this.searchItem.area.map(item => {
          if (item.level === '2') {
            arrArea.push(item.name);
          }
          if (item.level === '3') {
            arrTown.push(item.name);
          }
        });
      }
      let strArea = `${arrArea.join(',')}|#|in`;
      let strTown = `${arrTown.join(',')}|#|in`;
      if (this.searchItem.cherf_name !== '') {
        params.data.searchValue.personel_name = `${this.searchItem.cherf_name}|#|like`;
      }
      if (this.searchItem.river_name !== '') {
        params.data.searchValue.river_name = `${this.searchItem.river_name}|#|like`;
      }
      if(this.rowDate !== ''){
        params.data.searchValue.end_time = this.rowDate;
      }
      if (type === 1) {
        params.data.searchValue.patrol_type = '助理巡河';
      }
      ajaxPost(params);
    },
    exportData() {
      let params = {
        data: {
          basis: 2,
          searchValue: {
            patrol_is: '已结束',
            username: this.saveName,
          },
          order: { end_time: -1 },
        },
        token: storage.session.get('token'),
        url: this.urlDao,
        success: res => {
          let url2 = res.data.result;
          fetch(url2).then(res =>
            res.blob().then(blob => {
              let a = document.createElement('a');
              let url = window.URL.createObjectURL(blob);
              let filename = '巡查记录表';
              a.href = url;
              a.download = filename;
              a.click();
              window.URL.revokeObjectURL(url);
            })
          );
          this.spinShow = false;
        },
      };

      let arrArea = [];
      let arrTown = [];
      if (this.searchItem.area && this.searchItem.area.length > 0) {
        this.searchItem.area.map(item => {
          if (item.level === '2') {
            arrArea.push(item.name);
          }
          if (item.level === '3') {
            arrTown.push(item.name);
          }
        });
      }
      let strArea = `${arrArea.join(',')}|#|in`;
      let strTown = `${arrTown.join(',')}|#|in`;
      if (arrArea.length !== 0) {
        params.data.searchValue['location.area'] = strArea;
      }
      if (arrTown.length !== 0) {
        params.data.searchValue['location.town'] = strTown;
      }
      if(this.rowDate !== ''){
        params.data.searchValue.end_time = this.rowDate;
      }
      if (this.searchItem.cherf_name !== '') {
        params.data.searchValue.personel_name = `${this.searchItem.cherf_name}|#|like`;
      }
      if (this.searchItem.river_name !== '') {
        params.data.searchValue.river_name = `${this.searchItem.river_name}|#|like`;
      }
      if (this.saveType === 1) {
        params.data.searchValue.patrol_type = '助理巡河';
      }
      ajaxPost(params);
    },
    getAreaData(data) {
      this.searchItem.area = data;
    },
  },
  mounted() {
    let month = new Date().format('yyyy-MM');
    this.searchItem.time_sign = month;
    let year = new Date().getFullYear();
    this.searchItem.year = String(year);
    this.getData();
  },
};
</script>
